package com.example.Repository;

import com.example.domain.Blog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

//JpaSpecificationExecutor能实现动态组合查询
@Repository
public interface BlogRepository extends JpaRepository<Blog,Long>, JpaSpecificationExecutor<Blog> {

  @Modifying
  @Transactional
  @Query(value = "delete from Blog where id=?1")
  int DeteleBlogId(Long id);

  //全文搜索方法
  @Query(value = "from Blog b where b.title like ?1 or b.content like ?1")
  Page<Blog> findByQuery(String query, Pageable pageable);
}
